//获取到棋盘对象
let borad_box = $(".pannel");

//给棋盘对象添加格子
for (let i = 1; i <= 9; i++) {
  for (let j = 1; j <= 9; j++) {
    let tem = $("<div class='cell'></div>");
    tem.attr("data-x", i);
    tem.attr("data-y", j);
    borad_box.append(tem);
  }
}

//创建存放信息的数组
let info_arr = new Array();
init(info_arr);
setMine(info_arr);
print(info_arr);
// console.log(info_arr[1])

//绑定事件
let body_box = $("body");
//委托到整个页面
body_box.mousedown(function (evt) {
  //获取点击dom对象
  target = evt.target;
  // console.log(evt)

  //单元格点击事件
  if (target.className.includes("cell")) {
    let current_click = $(target);
    current_click.attr("class", "active");
    console.log(current_click.attr("data-x"));

    //显示数字或雷
    var x = current_click.attr("data-x");
    var y = current_click.attr("data-y");
    var surround = info_arr[x - 1][y - 1].surround;
    var state = info_arr[x - 1][y - 1].state;

    if (state === "safe") {
      let num_box = $(`<span class="num_box">${surround}<span>`);
      current_click.append(num_box);
    } else if (state === "danger") {
      let num_box = $(`<span class="mine_box">×<span>`);
      current_click.append(num_box);
    }
  }
});
